package com.far.api.controller;


import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


import com.far.util.PropertiesUtils;
import com.far.util.Q;

import cn.hutool.http.HttpUtil;


@RestController
@EnableAutoConfiguration
public class CommonController {
	


	@PostMapping(value = "/v1/{param1}", produces = "application/json; charset=utf-8")
	public String common1(@RequestBody String VO,
			@PathVariable(value = "param1") String param1
			) {
		System.out.println("===========进入1段通用接口1=================");
		System.out.println("param1:"+param1);
		System.out.println("VO:"+VO);
		
		String param1_url = PropertiesUtils.getProperty(param1);
		System.out.println("param1_url:"+param1_url);
		
	    
		
		String resp = HttpUtil.post(param1_url, VO); 
		
		//下面可以扩展自定义请求头
		//String sResp=  HttpUtil.createPost(sURL).body(VO).execute().charset("utf8").body();
		//String sResp = HttpUtil.createPost(sURL).header(Header.CONTENT_TYPE,"application/json").body(VO).execute().charset("utf8").body();
		//String sResp = HttpUtil.createPost(sURL).body(VO).execute().charset("utf8").body();
		
		//Map<String, String> hashMap = new HashMap<String, String>();
		//hashMap.put("token", "eyJhbGciOiJIUzI1NiIsIlR5cGUiOiJKd3QiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJIRF9BR1YiLCJleHAiOjE2ODMzNTYxNjJ9.Bz2S9QlZgJB6XqXO0KzUzqofLFd0z_vI5a_LoOTWOn0");

		System.out.println("===========返回结果========================");
		System.out.println("resp:"+resp);
		return resp;
	}
	
	
	
	//1段通用接口2:带token、订单序列号、时间戳
	@PostMapping(value = "/v2/{param1}", produces = "application/json; charset=utf-8")
	public String common2(@RequestBody String VO,
			@PathVariable(value = "param1") String param1,
			String token,
			String orderSerial,
			String timeStamp
			) {
		System.out.println("===========进入1段通用接口2=================");
		System.out.println("param1:"+param1);
		System.out.println("VO:"+VO);
		
		System.out.println("token:"+token);
		System.out.println("orderSerial:"+orderSerial);
		System.out.println("timeStamp:"+timeStamp);
	
		String param1_url = PropertiesUtils.getProperty(param1);
		
		if (!Q.isEmpty(token)) {
			 param1_url = param1_url + "?token="+token;
		}
		
		if (!Q.isEmpty(orderSerial)) {
			param1_url = param1_url + "&orderSerial="+orderSerial;
		}
		
		if (!Q.isEmpty(timeStamp)) {
			param1_url = param1_url + "&timeStamp="+timeStamp;
		}
		
		
		System.out.println("param1_url:"+param1_url);
		
	    
		
		String resp = HttpUtil.post(param1_url, VO); 
		
		//下面可以扩展自定义请求头
		//String sResp=  HttpUtil.createPost(sURL).body(VO).execute().charset("utf8").body();
		//String sResp = HttpUtil.createPost(sURL).header(Header.CONTENT_TYPE,"application/json").body(VO).execute().charset("utf8").body();
		//String sResp = HttpUtil.createPost(sURL).body(VO).execute().charset("utf8").body();
		
		//Map<String, String> hashMap = new HashMap<String, String>();
		//hashMap.put("token", "eyJhbGciOiJIUzI1NiIsIlR5cGUiOiJKd3QiLCJ0eXAiOiJKV1QifQ.eyJhdWQiOiJIRF9BR1YiLCJleHAiOjE2ODMzNTYxNjJ9.Bz2S9QlZgJB6XqXO0KzUzqofLFd0z_vI5a_LoOTWOn0");

		
		
		System.out.println("===========返回结果========================");
		System.out.println("resp:"+resp);
		return resp;
	}
	
	
	
	
	
	
	
	
	
	


//	
//
//	@PostMapping(value = "/{param1}/{param2}/{param3}/{param4}/{param5}/{param6}/{param7}", produces = "application/json; charset=utf-8")
//	public String common7(@RequestBody String VO, 
//			@PathVariable(value = "param1") String param1,
//			@PathVariable(value = "param2") String param2,
//			@PathVariable(value = "param3") String param3,
//			@PathVariable(value = "param4") String param4,
//			@PathVariable(value = "param5") String param5,
//			@PathVariable(value = "param6") String param6,
//			@PathVariable(value = "param7") String param7
//			) {
//		String domain7 = PropertiesUtils.getProperty("domain1");
//		String sURL = domain7+"/"+param1+"/"+param2+"/"+param3+"/"+param4+"/"+param5+"/"+param6+"/"+param7;
//		String sResp = HttpUtils.getHttp(sURL, VO);
//		return sResp;
//	}

}
